﻿#include "Drawer.h"

void debug(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
    std::cout << message << std::endl;
    if (severity == GL_DEBUG_SEVERITY_HIGH) {
        throw " ";
    }
}

void Drawer::initGL(size_t width, size_t height) {
    if (!glfwInit()) {
        throw std::runtime_error("GLFW init failed");
    }
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    GLFWwindow* window = glfwCreateWindow(width, height, "Music Light v0.3 Renderer", NULL, NULL);
    if (!window) {
        throw std::runtime_error("Window creation failed");
    }
    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
    glDebugMessageCallback(debug, nullptr);
    //glEnable(GL_DEBUG_OUTPUT);
    //glEnable(GL_BLEND);
    //glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}